﻿unit MainFrm;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
  Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Menus, System.UITypes,
  Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.Buttons, Vcl.CustomizeDlg, Vcl.ComCtrls,
  uBaseIntf, System.RTTI;

type
  TFrmMain = class(TSmartFrm)
    MainMenu1: TMainMenu;
    SysMenu: TMenuItem;
    CorpMenu: TMenuItem;
    AccMenu: TMenuItem;
    N1: TMenuItem;
    LevelMenu: TMenuItem;
    AreaMenu: TMenuItem;
    MoneyMenu: TMenuItem;
    N2: TMenuItem;
    PwdMenu: TMenuItem;
    N3: TMenuItem;
    ExitMenu: TMenuItem;
    StockMenu: TMenuItem;
    PartTypeMenu: TMenuItem;
    N4: TMenuItem;
    PartAMenu: TMenuItem;
    PartEMenu: TMenuItem;
    PartDMenu: TMenuItem;
    N5: TMenuItem;
    PartDetailMenu: TMenuItem;
    PartPriceMenu: TMenuItem;
    N6: TMenuItem;
    UnitDigitMenu: TMenuItem;
    StockInitMenu: TMenuItem;
    N7: TMenuItem;
    PrintPartMenu: TMenuItem;
    StockAEMenu: TMenuItem;
    TotalPartMenu: TMenuItem;
    InOutMenu: TMenuItem;
    PurMenu: TMenuItem;
    RepaireMenu: TMenuItem;
    PartBFMenu: TMenuItem;
    SellMenu: TMenuItem;
    XMenu: TMenuItem;
    PartBKMenu: TMenuItem;
    APMenu: TMenuItem;
    ARMenu: TMenuItem;
    ANMenu: TMenuItem;
    OtherMenu: TMenuItem;
    StatusBar1: TStatusBar;
    PageControl1: TPageControl;
    TabSheet0: TTabSheet;
    procedure ExitMenuClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure CorpMenuClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    CreateForm: ICreateForm;
    procedure ExitSys;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FrmMain: TFrmMain;

implementation

{$R *.dfm}

uses CreateSmartForm;

procedure TFrmMain.CorpMenuClick(Sender: TObject);
var
  CorpFrm: TForm;
  C: TRttiContext;
  T : TRttiInstanceType;
  V : TValue;
begin
  C := TRttiContext.Create();
  T := C.FindType('CorpFrm.TFrmCorp') as TRttiInstanceType;
  V := T.GetMethod('Create').Invoke(T.MetaClassType, [Application]);
  //(V.AsObject as TWinControl).Parent := self;
  CorpFrm := TForm(V.AsObject);
  CorpFrm.WindowState := wsMaximized;
  CorpFrm.Show;
end;

procedure TFrmMain.ExitMenuClick(Sender: TObject);
begin
  Self.ExitSys();
end;

procedure TFrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caNone;
  ExitSys();
end;

procedure TFrmMain.FormShow(Sender: TObject);
var
  C: TRttiContext;
  T : TRttiInstanceType;
  V : TValue;
begin
  if not Assigned(CreateForm) then
  begin
    C := TRttiContext.Create();
    T := C.FindType('CreateSmartForm.TCreateSmartForm') as TRttiInstanceType;
    V := T.GetMethod('Create').Invoke(T.MetaClassType, [Application]);
    CreateForm := TForm(V.AsObject) as ICreateForm;
  end;
  CreateForm.GetForm(Self, '', True);
end;

procedure TFrmMain.ExitSys;
begin
  if MessageBox(Self.Handle, '是否确认退出通用进销存管理系统(Smart)？', '确认退出',
    MB_OKCANCEL + MB_ICONQUESTION) = idOk then Application.Terminate;
end;

end.
